<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title><?php echo C('WEB_SITE_TITLE');?></title>
    <script>
        // 防止iframe
        if(self != top)
            top.location.replace(self.location);
    </script>
    <link rel="stylesheet" type="text/css" href="__CSS__/login.css" media="all">
   	<link rel="stylesheet" type="text/css" href="__CSS__/{$Think.config.COLOR_STYLE}.css" media="all">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/toastr/toastr.css" media="all">
</head>
<body id="login-page">
    <div id="main-content">

        <!-- 主体 -->
        <div class="login-body">
            <div class="login-main pr">
                <form action="{:U('doLogin')}" method="post" class="login-form">
                    <h3 class="welcome" style="margin-left: -40px"><img src="__PUBLIC__/images/logo.png" style="width:262px;display: block;margin:0 auto"><!--<?php echo C('WEB_SITE_TITLE');?>--></h3>
                    <div id="itemBox" class="item-box">
                        <div class="item">
                            <i class="icon-login-user"></i>
                            <input type="text" name="username" placeholder="请填写用户名" autocomplete="off" />
                        </div>
                        <div class="item b0">
                            <i class="icon-login-pwd"></i>
                            <input type="password" name="password" placeholder="请填写密码" autocomplete="off" />
                        </div>
                        
                        <div class="item verifycode">
                            <i class="icon-login-verifycode"></i>
                            <input type="text" name="verify" placeholder="请填写验证码" autocomplete="off">
                            <a class="reloadverify" title="换一张" href="javascript:void(0)">换一张？</a>
                        </div>
                        <span class="placeholder_copy placeholder_check">请填写验证码</span>
                        <div>
                            <img style="height: 40px;width: 100px;" class="verifyimg reloadverify" alt="点击切换" src="{:U('Public/verify')}">
                        </div> 
                    </div>
                    <div class="login_btn_panel">
                        <input type="hidden" name="security_code" id="security_code" value="{$security_code}">
                        <button class="login-btn" type="submit">
                            <span class="in"><i class="icon-loading"></i>登 录 中 ...</span>
                            <span class="on">登 录</span>
                        </button>
                        <div class="check-tips"></div>
                    </div>
                </form>
            </div>
        </div>
    </div>
	<!--[if lt IE 9]-->
    <script type="text/javascript" src="__JS__/jquery-1.10.2.min.js"></script>
    <!--[endif]-->
    <!--[if gte IE 9]-->
    <script type="text/javascript" src="__JS__/jquery-2.0.3.min.js"></script>
    <!--[endif]-->
    <script type="text/javascript" src="__PUBLIC__/assets/js/common.js"></script>
    <script type="text/javascript" src="__PUBLIC__/assets/js/hex_sha1.js"></script>
    <script type="text/javascript" src="__PUBLIC__/toastr/toastr.js" ></script>
    <script type="text/javascript">
    	/* 登陆表单获取焦点变色 */
    	$(".login-form").on("focus", "input", function(){
            $(this).closest('.item').addClass('focus');
        }).on("blur","input",function(){
            $(this).closest('.item').removeClass('focus');
        });

    	//表单提交
    	$(document)
	    	.ajaxStart(function(){
	    		$("button:submit").addClass("log-in").attr("disabled", true);
	    	})
	    	.ajaxStop(function(){
	    		$("button:submit").removeClass("log-in").attr("disabled", false);
	    	});

    	$("form").submit(function(){
    		var self = $(this);
            var username = $('input[name="username"]');
            var password = $('input[name="password"]');
            
            if (username.val().length < 4 || username.val().length >= 20 ) {
                toastr.error('用户名输入错误');
                username.focus();
                return false;
            }
            if (password.val().length < 4 || password.val().length > 44) {
                toastr.error('密码输入错误');
                password.focus();
                return false;
            }
            // 对发送出去的代码进行加密,  如果超过40位, 当做已经加密过, 不再加密
            if (password.val().length < 40) {
                password.val( hex_sha1(password.val()) );
                //console.log(hex_sha1(password.val()));
            }

    		$.post(self.attr("action"), self.serialize(), function(data){
                // console.log(data);
    			if(data.status == 1){
    				window.location.href = "{:U('Admin/Index/index')}";
    			} else {
                    password.val('');
    				toastr.error(data.info);
    				//刷新验证码
    				$(".reloadverify").click();
    			}
    		}, "json");

            return false;
    	});

		$(function(){
			//初始化选中用户名输入框
			$("input[name='username']").focus();
			//刷新验证码
			var verifyimg = $(".verifyimg").attr("src");
            $(".reloadverify").click(function(){
                if( verifyimg.indexOf('?')>0){
                    $(".verifyimg").attr("src", verifyimg+'&random='+Math.random());
                }else{
                    $(".verifyimg").attr("src", verifyimg.replace(/\?.*$/,'')+'?'+Math.random());
                }
            });
		});
    </script>
</body>
</html>
